package com.ruoyi.yyq.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

//import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.yyq.domain.CarGesStation;
import com.ruoyi.yyq.service.ICarGesStationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 加油站Controller
 * 
 * @author ruoyi
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/GesStation")
@CrossOrigin
public class CarGesStationController extends BaseController
{
    @Autowired
    private ICarGesStationService carGesStationService;

    /**
     * 查询加油站列表
     */
    @RequiresPermissions("yyq:GesStation:list")
    @GetMapping("/list")
    public TableDataInfo list(CarGesStation carGesStation)
    {

        startPage();
        List<CarGesStation> list = carGesStationService.selectCarGesStationList(carGesStation);
        return getDataTable(list);
    }

    /**
     * 导出加油站列表
     */
    @RequiresPermissions("yyq:GesStation:export")
    @Log(title = "加油站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarGesStation carGesStation)
    {
        List<CarGesStation> list = carGesStationService.selectCarGesStationList(carGesStation);
        ExcelUtil<CarGesStation> util = new ExcelUtil<CarGesStation>(CarGesStation.class);
        util.exportExcel(response, list, "加油站数据");
    }

    /**
     * 获取加油站详细信息
     */
    @RequiresPermissions("yyq:GesStation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carGesStationService.selectCarGesStationById(id));
    }

    /**
     * 新增加油站
     */
    @RequiresPermissions("yyq:GesStation:add")
    @Log(title = "加油站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarGesStation carGesStation)
    {
        return toAjax(carGesStationService.insertCarGesStation(carGesStation));
    }

    /**
     * 修改加油站
     */
    @RequiresPermissions("yyq:GesStation:edit")
    @Log(title = "加油站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarGesStation carGesStation)
    {
        return toAjax(carGesStationService.updateCarGesStation(carGesStation));
    }

    /**
     * 删除加油站
     */
    @RequiresPermissions("yyq:GesStation:remove")
    @Log(title = "加油站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carGesStationService.deleteCarGesStationByIds(ids));
    }

    /**
     * 根据汽油种类查询加油站列表
     */
    @RequiresPermissions("yyq:GesStation:list")
    @GetMapping("/listByGasType/{gasTypeId}")
    public TableDataInfo listByGasType(@PathVariable Long gasTypeId) {
        startPage();
        List<CarGesStation> list = carGesStationService.selectCarGesStationListByGasType(gasTypeId);
        return getDataTable(list);
    }
}
